#include <bits/stdc++.h>
using namespace std;
long long n;
int len, d[20];
long long backup[20][2];


long long dfs(int depth, int now, int father, bool border) {
  if (depth > len)
    return 1;
  if (now == 3 && father == 1)
    return 0;


  int k = len + 1 - depth;
  if (!border && backup[k][now == 1] != -1)
    return backup[k][now == 1];

  // 最大能达到多少
  int maxD = border ? d[depth] : 9;
  long long ans = 0;
  for (int son = 0; son <= maxD; son++) {
    // 搜下一层，  father 是谁 ， 是否是边界，不是边界可以0.。。。9
    ans += dfs(depth + 1, son, now, border && son == d[depth + 1]);
  }
  if (!border) {
    backup[k][now == 1] = ans;
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  len = s.size();
  for (int i = 0; i < len; i++) {
    d[i + 1] = s[i] - '0';
  }
  memset(backup, -1, sizeof(backup));
  int ans = dfs(0, -1, -1, true);
  cout << ans << endl;
  return 0;
}